//
//  DefaultAddressCell.m
//  KuWoCan
//
//  Created by hwd on 17/3/14.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "DefaultAddressCell.h"

@interface DefaultAddressCell ()

@property (nonatomic) UILabel *defaultPromptLabel;
@end

//默认地址单元格

@implementation DefaultAddressCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setUpUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setUpUI
{
    UIImageView *pointImg = [[UIImageView alloc] init];
    pointImg.image = kImg(@"dizhi");
    [self addSubview:pointImg];
    [pointImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(8 * screenW_6));
        make.top.equalTo(@(11 * screenW_6));
        make.size.mas_equalTo(CGSizeMake(25 * screenW_6, 25 * screenW_6));
    }];
    
    _nameLab = [UILabel new];
    _nameLab.textColor = [UIColor grayColor];
    _nameLab.font = [UIFont systemFontOfSize:14.0];
    _nameLab.textAlignment = NSTextAlignmentLeft;
    _nameLab.text = @"";
    [self addSubview:_nameLab];
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pointImg.mas_right).offset(10);
        make.height.equalTo(@15);
        make.top.equalTo(pointImg.mas_top);
    }];
    
    _teleLab = [UILabel new];
    _teleLab.textColor = [UIColor grayColor];
    _teleLab.font = [UIFont systemFontOfSize:14.0];
    _teleLab.textAlignment = NSTextAlignmentLeft;
    _teleLab.text = @"";
    [self addSubview:_teleLab];
    [_teleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nameLab.mas_right).offset(20);
        make.height.equalTo(@14);
        make.top.equalTo(pointImg.mas_top);
    }];
    
    UIImageView *nextImg = [[UIImageView alloc] init];
    nextImg.image = kImg(@"next");
    [self addSubview:nextImg];
    [nextImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pointImg.mas_top);
        make.right.equalTo(@-20);
        make.size.mas_equalTo(CGSizeMake(12, 15));
    }];
    
    _fourthLab = [UILabel new];
    _fourthLab.textColor = [UIColor grayColor];
    _fourthLab.font = [UIFont systemFontOfSize:14.0];
    _fourthLab.textAlignment = NSTextAlignmentLeft;
    _fourthLab.text = @"";
    [self addSubview:_fourthLab];
    [_fourthLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nameLab.mas_left);
        make.height.equalTo(@14);
        make.top.equalTo(_nameLab.mas_bottom).offset(10);
    }];

    self.defaultPromptLabel = [UILabel new];
    self.defaultPromptLabel.text = @"你还没有添加地址";
    self.defaultPromptLabel.textColor = [UIColor grayColor];
    self.defaultPromptLabel.font = [UIFont systemFontOfSize:14.0];
    [self addSubview:self.defaultPromptLabel];
    [self.defaultPromptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(pointImg.mas_centerY);
        make.left.equalTo(pointImg.mas_right).offset(10);
        make.right.equalTo(self);
    }];
    
    UIImageView *lineImg = [[UIImageView alloc] init];
    lineImg.image = kImg(@"xinfeng");
    [self addSubview:lineImg];
    [lineImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(_fourthLab.mas_bottom).offset(15);
        make.height.equalTo(@8);
    }];


    UIView *bgView= [UIView new];
    bgView.backgroundColor = KwBgColor;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(lineImg.mas_bottom);
        make.height.equalTo(@15);
        make.bottom.equalTo(@0);
    }];
}

- (void)setModel:(AddressModel *)model
{
    self.defaultPromptLabel.hidden = YES;
    _model = model;
    _nameLab.text = model.name;
    _teleLab.text = model.phone;
    _fourthLab.text = [NSString stringWithFormat:@"%@%@",model.region,model.address];
}

- (void)setDetailModel:(OrderDetailInfoModel *)detailModel
{
    self.defaultPromptLabel.hidden = YES;
    _detailModel = detailModel;
    _nameLab.text = detailModel.userName;
    _teleLab.text = detailModel.userPhone;
    _fourthLab.text = [NSString stringWithFormat:@"%@",detailModel.userAddress];
}

@end
